import random
import sys
import os
import time

playerName = ""
playerClass = ""
playerHealth = 100
enemyHealth = 100
previousLocal = ""
playerGold = 0

def goBack():
    if previousLocal == "part1":
        part1()
    elif previousLocal == "part1Encounter1":
        part1Encounter1()
    elif previousLocal == "part2":
        part2()

def clear():
    os.system('cls')

def main():
    print ("Would you like to start a new journey, return to your previous point,\
or leave?  (please type new, load, or exit.)")
    gameChoice = input()
    if gameChoice == "new":
        newGame()
    elif gameChoice == "load":
        loadGame()
    elif gameChoice == "exit":
        quit()
    else:
        clear()
        main()

def newGame():
    global playerClass
    print ("What is your name?")
    playerName = input()
    print ("Hello " + playerName)
    print ("Are you a sorcerer, a warrior, or an assassin? \
(type sorcerer, warrior, or assassin)")
    playerClass = input()
    print ("You are a", playerClass)
    while playerClass == "":
        print ("Are you a sorcerer, a warrior, or an assassin? \
(type sorcerer, warrior, or assassin)")
        playerClass = input()
    else:
        clear()
        part1()    

def part1():
    global previousLocal
    previousLocal = part1
    print ("Walking into a dark forest, you see a path going left, \
and a path going straight. Which path would you like to take?")
    path1 = input()
    if path1 == "straight":
        part1Encounter1()
    elif path1 == "left":
        print ("Turning left, you trip over a log. Falling down, \
you hit your head on a rock and start bleeding.")
        global playerHealth
        playerHealth = playerHealth - 2
        print ()
        print ("After getting up and tying a piece of cloth around your wound, \
you continue onward. ")
        os.system('pause')


def part1Encounter1():
    global previousLocal
    previousLocal = part1Encounter1
    print ("Continuing onward, you encounter a lone traveller.")
    print ("Do you approach him?[Y/N]")
    encounter1 = input()
    if encounter1.lower() == 'y':
        global playerClass
        if playerClass.lower() == 'sorcerer':
            print ("As you approach, the traveller lunges at you with a staff")
            magicCombat()
        elif playerClass.lower() == 'warrior':
            print ("As you approach, the traveller lunges at you with a staff")
            meleeCombat()
        elif playerClass.lower() == 'assassin':
            print ("As you approach, the traveller lunges at you with a staff")
            stealthCombat()
    elif encounter1.lower() == 'n':
        clear()
        print ("Ignoring the traveller, you trek onwards")
    else:
        clear()
        part1Encounter1()

#def combatChoice():
#    global playerClass
#    if playerClass.lower() == 'sorcerer':
#        print ("As you approach, the traveller lunges at you with a staff")
#        magicCombat()
#    elif playerClass.lower() == 'warrior':
#        print ("As you approach, the traveller lunges at you with a staff")
#        meleeCombat()
#    elif playerClass.lower() == 'assassin':
#        print ("As you approach, the traveller lunges at you with a staff")
#        stealthCombat()

def magicCombat():
    global enemyHealth
    elements = ['fire', 'ice', 'electricity']
    while enemyHealth >= 0:
        print ("You blast "+random.choice(elements)+" from your hands, damaging the enemy")
        input("Press enter to attack again")
        enemyHealth -= random.randint(15, 30)
        clear()
        print ("The enemy swipes at you with his weapon")
        playerDodgeChance = randint(0, 10)
        if playerDodgeChance <= 2:
            print()
            print ("You jump back, dodging his strike")
        else:
            print()
            print ("You were too slow! His blow lands on you.")
            playerHealth -= random.randint(5, 10)        
    else:
        if enemyHealth <= 0:
            print ("You killed your opponent. Do you wish to loot him?")
            loot = input('y/n')
            if loot.lower == 'y':
                loot()
            else:
                goBack()

def sneakCombat():
    global enemyHealth
    critChance = random.randint(1, 100)
    attack = 1
    while enemyHealth != 0 and attack == 1:
        print ("You sneak up behind your opponent, and lunge at him with \
your dagger.")
        enemyHealth = (enemyHealth - (equipedWeapon.damage*10))
        attack += 1
    else:
        if enemyHealth != 0 and attack > 1 and critChance >= 98:
            print("You slash at your opponent, landing a lucky blow.")
            enemyHealth -= (equipedWeapon.damage*3)
            attack +=1
            input()
        elif enemyHealth != 0 and attack > 1:
            print("You slash at your opponent.")
            enemyHealth -= equipedWeapon.damage
            attack +=1
            input()
        elif enemyHealth == 0:
            print ("You killed your opponent. Do you wish to loot him?")
            loot = input('y/n')
            if loot.lower == 'y':
                loot()
            else:
                goBack()

def loot():
    global playerGold
    foundGold = random.randint(0, 10)
    print ("You find ", foundGold, " on the body")
    playerGold =+= foundGold
                
            

def meleeCombat(self):
    global enemyHealth
    pass

class weapon(object):
    def __stats__(self, weaponName, damage, worth, equipped):
        self.weaponType = weaponType
        self.damage = damage
        self.worth = worth
        self.equipped = equipped

class equippedWeapon(weapon):
    pass

ironDagger = equippedWeapon()
ironDagger.weaponName = "Iron Dagger"
ironDagger.damage = random.uniform(.2, 10)
ironDagger.worth = 5
if playerClass == "assassin" and ("Dagger") in equippedWeapon.name:
    ironDagger.equipped = "yes"
else:
    ironDagger.equipped = "no"



main()
